package com.slowfly.rule.engine.features.field;


import com.google.common.collect.Lists;
import com.slowfly.rule.engine.annotations.FeatureClass;
import com.slowfly.rule.engine.entity.Feature;
import com.slowfly.rule.engine.features.BaseFeatureClass;
import com.slowfly.rule.engine.param.ListFeaturesParam;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Objects;

import static com.baomidou.mybatisplus.core.toolkit.StringPool.COMMA;


@Slf4j
@FeatureClass(code = "comma_field_feature_class", name = "逗号字段特征")
public class CommaFieldFeatureClass extends BaseFeatureClass {

    public Object getFeatureValue(ListFeaturesParam param, Feature feature) {
        List<String> featureValues = Lists.newArrayList();
        for (String path : feature.getParam().split(COMMA)) {
            Object featureValue = getFeatureValue(param.getRiskParam(), path);
            if (Objects.nonNull(featureValue)) {
                featureValues.add(featureValue.toString());
            }
        }
        return String.join(COMMA, featureValues);
    }
}
